*Decentralization causes SA Figure 6 (model 3)*
*DO FILE TO CREATE MARGINAL EFFECTS GRAPHs*



#delimit ;
mixed raiapproved subnatcoalvote_lg coalgovtvote_lg  natcoalXsubnatcoal_lg raiapproved_lg if subtiminginbet_lg==1  || countryno: || regionno: ;





 
*     ****************************************************************  *;
*              railevel  i.e. x2 = MV                               *;
*     ****************************************************************  *;
generate MV=((_n-1)/10);    

replace MV=. if _n>4000;

matrix b=e(b);
matrix list e(b);
matrix V=e(V);
matrix list e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1];
scalar varb3=V[3,3];
scalar covb1b3=V[1,3];


scalar list b1 b2 b3 varb1 varb3 covb1b3;

gen conb=b1+b3*coalgovtvote_lg if _n<4000;



*     ****************************************************************  *;
*      These create conditional coefficients for b1 at MV        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*coalgovtvote_lg^2+2*covb1b3*coalgovtvote_lg)  if _n<4000;
set more off;
gen cont= conb/conse;


*     ****************************************************************  *;
*      This creates a conditional t                                                  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Generate confidence intervals at the 95% level                  *;
*     ****************************************************************  *;
*     ****************************************************************  *;

gen a=1.96*conse;
gen upper=conb+a;
gen lower=conb-a;
set textsize 100;


*gen a=1.645*conse;*
*gen upper=conb+a;*
*gen lower=conb-a;*
*set textsize 100;*;

label variable conb "Marginal Effect of Subnational Election Vote Share";
label variable upper "95% CI - upper bound";
label variable lower "95% CI - lower bound";
label variable coalgovtvote_lg "National Election Vote Share";



*     ****************************************************************  *;
*       Graph    *;
*                                          *;
*     ****************************************************************  *;
*this gives the full range*;



#delimit ;
gen where=-.0395;
gen pipe = "|";
egen tag_natcoal=tag(coalgovtvote_lg) if M3obs==1;

#delimit ;

sort coalgovtvote_lg;


twoway (line conb coalgovtvote_lg, clpat(solid)) (line upper coalgovtvote_lg, clpat(shortdash)) (line lower coalgovtvote_lg, clpat(shortdash)), yline(0) ytitle("Conditional Coefficient of Subnational Election Vote Share") legend(off), scatter where coalgovtvote_lg if tag_natcoal, plotr(m(b4)) ms(none) mlabcolor(gs5) mlabel (pipe) mlabpos(6);

clear;
